/**
 * @module 上传
 */
const appConfig = require('../app.config.js');
const path = require('path');
const uploadPath = path.resolve(path.join(process.cwd(), appConfig.staticPath, appConfig.uploadPath));
const multer = require('koa-multer');
const storage = multer.diskStorage({

    //文件保存路径
    destination (req, file, cd){
        cd(null, uploadPath)
    },

    // 文件名称
    filename (req, file, cd){
        let fileFormat = (file.originalname).split('.')
        let time = new Date();
        cd(null, `${time.getTime()}.${fileFormat.pop()}`);
    }
    
})

const upload = multer({storage})

module.exports = upload;
